// import { stringToBytes } from "../../../utils/weichatPb/src/util";

const app = getApp()
const util = require('../../../utils/util.js')
const lbbService = require('../../../pages/service/service.js')
var Base64 = require('../../../utils/base64.js')

Component({
    /**
     * 组件的属性列表
     */
    properties: {
        hospitalId: {
            type: Number
        },
        hospitalName: {
            type: String
        },
        macId: {
            type: String
        },
        location: {
            type: String
        },
        equipType: {
            type: String,
            value: 'pile'
        },
        equipCode: {
            type: String
        },
        gatewayMac: {
            type: String
        },
        gatewayHid: {
            type: String
        },
        nowStat: {
            type: Number
        },
        partList: {
            type: Array,
            value: []
        },
        tailRecord: {
            type: Object
        },
        btns: {
            type: Array,
            value: ['changeLocation', 'offLine', 'maintain', 'changeBtr', 'statusDetail']
        },
        modalText: {
            type: String,
        },
        lostClassification: {
            type: Array,
            value: [{
                text: '其它',
                value: 0
            }, ],
        },
    },
    /**
     * 组件的初始数据
     */
    data: {
        offPileShow: false, //下线控制盒
        offEquipShow: false, //下线设备
        batteryShow: false, //更换电池
        partsShow: false, //更换配件
        confirShow: false, //确认丢失
        changeRfidShow: false, //更换rfid
        textareaShow: false,
        batteryType: '1', // 0干电池；1锂电池
        batteryTips: '',
        partsType: '', //pile:桩位配件
        equipOffTypes: [], //下线原因数组
        equipOffType: '', //下线原因
    },
    attached: function () {
        let that = this;
        if (that.data.equipType == 'pile') {
            that.getOffPileTypes();
        } else {
            that.getOffEquipTypes();
        }
    },
    ready: function () {
        let that = this;
        that.toast = that.selectComponent("#toast");
        that.personalModal = that.selectComponent("#personalModal");
    },
    /**
     * 组件的方法列表
     */
    methods: { //option的显示与否
        /**
         * 防止冒泡
         */
        stopMaoPao: function () {
            return;
        },
        toTakePhoto() {
            console.log(this.data.hospitalId, 'this.data.hospitalId', this.data.equipCode)
            wx.navigateTo({
                url: '/pages/SCM/takePhoto/takePhoto?hospitalId=' + this.data.hospitalId + '&pileCode=' + this.data.equipCode,
            })
        },
        toTakePhotoRecord() {
            console.log(this.data.hospitalId, 'this.data.hospitalId', this.data.equipCode)
            wx.navigateTo({
                url: '/pages/SCM/takePhotoRecord/takePhotoRecord?hospitalId=' + this.data.hospitalId + '&pileCode=' + this.data.equipCode,
            })
        },
        toTakePhotoed() {
            console.log(this.data.hospitalId, 'this.data.hospitalId', this.data.equipCode)
            wx.navigateTo({
                url: '/pages/SCM/takePhoto/takePhoto?hospitalId=' + this.data.hospitalId + '&equId=' + this.data.equipCode,
            })
        },
        toTakePhotoRecorded() {
            if ((this.data.equipCode).indexOf("L") > -1) {
                var arr = this.data.equipCode.split('')
                var str = ''
                for (let i = 0; i < arr.length; i++) {
                    if (arr[i] == 'L') {} else {
                        str += arr[i]
                    }
                }
                arr.join('')
                this.setData({
                    equipCode: str
                })
            }
            wx.navigateTo({
                url: '/pages/SCM/takePhotoRecord/takePhotoRecord?hospitalId=' + this.data.hospitalId + '&equId=' + this.data.equipCode,
            })
        },
        //跳转到网关设备关系信息
        toGatewayEquShip: function (e) {
            let that = this
            wx.navigateTo({
                url: '/pages/gateway/equShip/equShip?equId=' + that.data.gatewayHid + "&mac=" + that.data.gatewayMac + "&position=" + that.data.location +
                    '&equHid=' + that.data.equipCode.replace('Z', ''),
            })
        },
        /**
         * 图片预览
         */
        preViewImgs: function (e) {
            let current = e.currentTarget.dataset.current;
            let urls = e.currentTarget.dataset.urls;
            util.previewImgs(current, urls);
        },
        /**
         * 获取桩的下线类型
         */
        getOffPileTypes: function () {
            let that = this;
            let equipOffTypes = [];
            lbbService.getEquOfflineReason({}, function (res) {
                Object.keys(res.data).forEach(function (key) {

                    (key == 1) && that.setData({
                        equipOffType: res.data[key]
                    });
                    equipOffTypes.push({
                        name: res.data[key],
                        value: key,
                        checked: key == 1
                    })

                })
                equipOffTypes.push({
                    name: '其他',
                    value: 0,
                    checked: false
                })
                that.setData({
                    equipOffTypes: equipOffTypes
                })
            })
        },

        /**
         * 获取设备的下线类型
         */
        getOffEquipTypes: function () {
            let that = this;
            let equipOffTypes = [];
            lbbService.getEquipmentOffReason({}, function (res) {
                Object.keys(res.data).forEach(function (key) {

                    (key == 1) && that.setData({
                        equipOffType: res.data[key]
                    });
                    equipOffTypes.push({
                        name: res.data[key],
                        value: key,
                        checked: key == 1
                    })

                })
                equipOffTypes.push({
                    name: '其他',
                    value: 0,
                    checked: false
                })
                that.setData({
                    equipOffTypes: equipOffTypes
                })
            })
        },
        /**
         * 显示下线桩位modal
         */
        showOffPileModal: function () {
            let that = this;
            that.setData({
                offPileShow: true
            })
        },
        /**
         * 隐藏下线桩位modal
         */
        hideOffPileModal: function () {
            let that = this;
            that.setData({
                offPileShow: false,
                textareaShow: false
            })
        },
        /**
         * 显示更换电池的modal
         */
        showBatteryModal: function () {
            let that = this;
            lbbService.getLosingPowerFast({
                hid: that.data.equipCode
            }, res => {
                if (res.data == 0) {
                    that.setData({
                        batteryShow: true
                    })
                } else {
                    let modalText = res.description;
                    that.personalModal.showModal(modalText, function () {});
                }
            })
        },
        hideBatteryModal: function () {
            let that = this;
            that.setData({
                batteryShow: false,
                batteryTips: '',
                batteryId: '',
                batteryType: '1'
            })
        },
        /**
         * 显示下线桩位modal
         */
        showPartsModal: function () {
            let that = this;
            that.setData({
                partsShow: true
            })
        },
        /**
         * 隐藏下线桩位modal
         */
        hidePartsModal: function () {
            let that = this;
            that.setData({
                partsShow: false,
                partsType: '',
                partList: [],
            })
            that.triggerEvent('deletemypartlist');
        },
        /**
         * 隐藏丢失原因
         */
        hideConfirmModal: function () {
            let that = this;
            that.setData({
                confirShow: false,
                reasonFroLoss: '',
                classification: '0',
            })
        },
        /**
         * 显示下线轮椅modal
         */
        showOffEquipModal: function () {
            let that = this;
            that.setData({
                offEquipShow: true
            })
        },
        /**
         * 隐藏下线轮椅modal
         */
        hideOffEquipModal: function () {
            let that = this;
            that.setData({
                offEquipShow: false,
                textareaShow: false
            })
        },
        /**
         * 桩位/轮椅下线原因变化
         */
        offTypeChange: function (e) {
            let equipOffType = e.detail.value;
            let flg = false;
            if (equipOffType == '其他') {
                flg = true;
            }
            this.setData({
                equipOffType: equipOffType,
                textareaShow: flg
            })
        },
        /**
         * 输入轮椅/桩位下线原因
         */
        inputOffDesc: function (e) {
            let desc = e.detail.value;
            this.setData({
                equipOffType: desc
            })
        },
        /**
         * 选择原因类型
         */
        myEventListener: function (e) {
            console.log('类型', e.detail[5])
            this.setData({
                classification: e.detail[5]
            })
        },
        /**
         * 输入更换配件的备注信息
         */
        inputPartsDesc: function (e) {
            let desc = e.detail.value;
            this.setData({
                partsReason: desc
            })
        },
        /**
         * 输入丢失的原因
         */
        inputReasonLoss: function (e) {
            let desc = e.detail.value;
            this.setData({
                reasonFroLoss: desc
            })
        },
        /**
         * 选择配件类型
         */
        partsTypeChange: function (e) {
            let that = this;
            let type = e.detail.value;
            that.setData({
                partsType: type
            })
        },
        /**
         * 下线桩位
         */
        offPile: function () {
            let that = this;
            if (that.data.equipOffType == "其他") {
                that.toast.showToast('请输入备注');
                return;
            }
            that.hideOffPileModal();
            lbbService.updatePileStat({
                equId: parseInt(that.data.equipCode),
                nowStat: 2,
                lbmid: parseInt(that.data.hospitalId),
                reason: that.data.equipOffType
            }, function (res) {
                that.toast.showToast('下线成功', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },

        /**
         * 下线轮椅
         */
        offEquip: function () {
            let that = this;
            if (that.data.equipOffType == "其他") {
                that.toast.showToast('请输入备注');
                return;
            }
            that.hideOffEquipModal();
            lbbService.updateEquStat({
                equId: parseInt(that.data.equipCode.replace(/[^0-9]/ig, "")),
                nowStat: 2,
                lbmid: parseInt(that.data.hospitalId),
                reason: that.data.equipOffType
            }, function (res) {
                that.toast.showToast('下线成功', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },
        /**
         * 变更桩位位置
         */
        changePileLocation: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let hospitalId = that.data.hospitalId;
            let hospitalName = that.data.hospitalName;
            let location = that.data.location;
            wx.navigateTo({
                url: '/pages/changePileLocation/changePileLocation?pileCode=' + equipCode + '&hospitalId=' + hospitalId + '&hospitalName=' + hospitalName + '&location=' + location
            })
        },
        /**
         * 变更设备位置
         */
        changeEquipLocation: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let equipType = that.data.equipType;
            let hospitalId = that.data.hospitalId;
            let hospitalName = that.data.hospitalName;
            wx.navigateTo({
                url: '/pages/changeEquipLocation/changeEquipLocation?equipCode=' + equipCode + '&hospitalId=' + hospitalId + '&hospitalName=' + hospitalName + '&equipType=' + equipType
            })
        },
        /**
         * 维修桩位
         */
        maintain: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let hospitalId = that.data.hospitalId;
            let hospitalName = that.data.hospitalName;
            let location = that.data.location;
            wx.navigateTo({
                url: '/pages/maintain/maintain?pileCode=' + equipCode + '&hospitalName=' + hospitalName + '&location=' + location + '&hospitalId=' + hospitalId,
            })
        },
        /**
         * 查看维修中的桩位
         */
        maintainFinish: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let hospitalId = that.data.hospitalId;
            let hospitalName = that.data.hospitalName;
            let location = that.data.location;
            wx.navigateTo({
                url: '/pages/maintaining/maintaining?pileCode=' + equipCode + '&hospitalId=' + hospitalId + '&hospitalName=' + hospitalName
            })
        },
        /**
         * 维修设备
         */
        maintainEquip: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let hospitalName = that.data.hospitalName;
            let hospitalId = that.data.hospitalId;
            wx.navigateTo({
                url: '/pages/maintainEquip/maintainEquip?equipCode=' + equipCode + '&hospitalName=' + hospitalName + '&hospitalId=' + hospitalId
            })
        },
        /**
         * 查看维修中的设备
         */
        maintainEquipFinish: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            let hospitalName = that.data.hospitalName;
            let hospitalId = that.data.hospitalId;
            wx.navigateTo({
                url: '/pages/maintainingEquip/maintainingEquip?equipCode=' + equipCode + '&hospitalName=' + hospitalName + '&hospitalId=' + hospitalId
            })
        },
        /**
         * 输入电池编号
         */
        inputBatteryId: function (e) {
            let batteryId = e.detail.value;
            this.setData({
                batteryId: batteryId
            })
        },
        /**
         * 选择电池类型
         */
        batteryTypeChange: function (e) {
            let that = this;
            console.log('batteryTypeChange', e)
            let type = e.currentTarget.dataset.type;
            console.log('batteryTypeChange', e)
            that.setData({
                batteryType: type,
                batteryTips: '',
                batteryId: ''
            });
            console.log('batteryTypeChange', e)
        },
        /**
         * 提交电池
         */
        batterySubmit: function (e) {
            let that = this;
            if (that.data.batteryType == '1') {
                var r = /^\+?[1-9][0-9]*$/;
                if (!r.test(that.data.batteryId)) {
                    console.log(that.data.batteryId);
                    that.setData({
                        batteryTips: '请输入正确的数字编号'
                    });
                    return false;
                }
            }

            let optPileId = parseInt(that.data.equipCode.replace(/[^0-9]/ig, ""));
            let param = {
                optPileId: optPileId
            };
            if (that.data.batteryType == '1') { //新电池
                param.type = 1;
                param.upwardBatteryId = that.data.batteryId;
            } else {
                param.type = 0;
                param.upwardBatteryId = 0;
            }
            lbbService.changePileBattery(param, function (res) {
                if (res.result == 0) {
                    that.toast.showToast('更换成功', 'success');
                    that.hideBatteryModal();
                    setTimeout(function () {
                        that.triggerEvent('getequipinfo');
                    }, 2000)
                } else if (res.result > 0) {
                    that.setData({
                        batteryTips: '请先将电池绑定的控制盒Z' + res.result + '下线'
                    });
                } else if (res.result == -2) {
                    that.setData({
                        batteryTips: '输入的电池不存在'
                    });
                }

            })
        },
        /**
         * 扫码获取电池编号
         */
        scanQrCode: function () {
            let that = this;
            wx.scanCode({
                success(res) {
                    that.setData({
                        batteryId: res.result.replace(/[^0-9]/ig, "")
                    });
                }
            })
        },
        /**
         * 删除某一项配件
         */
        deleteParts: function (e) {
            let that = this;
            let id = e.currentTarget.dataset.id;
            console.log('deleteparts', id);
            that.triggerEvent('deleteparts', id);
        },
        /**
         * 去选择配件
         */
        toSelectParts: function () {
            let that = this;

            if (that.data.equipType == 'pile' && !that.data.partsType) {
                that.toast.showToast('请选择配件类型');
                return;
            } else if (that.data.equipType != 'pile') {
                that.data.partsType = that.data.equipType;
            }
            wx.navigateTo({
                url: '/pages/partList/partList?type=' + that.data.partsType + '&partList=' + JSON.stringify(that.data.partList),
            })
        },
        /**
         * 更换配件
         */
        replaceParts: function () {
            let that = this;
            let equType = 'pile';
            let replaceInfo = [];
            that.data.partList.forEach((item) => {
                let partItem = {};
                partItem[item.accName] = item.accNum;
                replaceInfo.push(partItem);
            })
            if (that.data.partsType == 'box') {
                equType = 'box';
            } else if (that.data.partsType == 'chair') {
                equType = 'chair';
            } else if (that.data.partsType == 'car') {
                equType = 'hospital_trolley';
            }

            lbbService.replaceParts({
                replaceInfo: JSON.stringify(replaceInfo),
                lbmId: parseInt(that.data.hospitalId),
                equType: equType,
                equId: parseInt(that.data.equipCode),
                reason: that.data.partsReason ? that.data.partsReason : ''
            }, function (res) {
                if (res.result == 0) {
                    that.toast.showToast('更换成功', 'success');
                    that.hidePartsModal();
                    setTimeout(function () {
                        that.triggerEvent('getequipinfo');
                    }, 2000)
                }
            })
        },
        //标记月租
        showModal7: function () {
            let that = this;
            let modalText = '确定标记' + that.data.equipInfo.equipCode + '为月租吗？';
            that.personalModal.showModal(modalText, that.rentByMonth);
        },
        rentByMonth: function () {
            let that = this;
            let equipCode = that.data.equipInfo.equipCode.replace(/[^0-9]/ig, "");
            lbbService.rentByMonth({
                equId: equipCode
            }, function (res) {
                that.toast.showToast('已标记月租', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },
        /**
         * 显示替换控制盒modal
         */
        showChangeBoxModal: function () {
            this.setData({
                changeBoxShow: true
            })
        },
        /**
         * 隐藏替换控制盒modal
         */
        hideChangeBoxModal: function () {
            this.setData({
                changeBoxShow: false
            })
        },
        /**
         * 显示替换二维码modal
         */
        showChangeCodeModal: function () {
            this.setData({
                changeCodeShow: true
            })
        },
        /**
         * 隐藏替换二维码modal
         */
        hideChangeCodeModal: function () {
            this.setData({
                changeCodeShow: false,
                smallCode: '',
                largeCode: '',
                qc: ''
            })
        },
        /**
         * 显示替换rfid的modal
         */
        showChangeRfidModal: function () {
            let that = this;
            that.setData({
                changeRfidShow: true,
            })
        },
        /**
         * 隐藏替换rfid的modal
         */
        hideChangeRfidModal: function () {
            this.setData({
                changeRfidShow: false,
                rfidCode: '',
                newEquipCode: '',
            })
        },
        /**
         * 显示恶意不归还confirm
         */
        showNoReturnConfirm: function () {
            let that = this;
            let modalText = '确定将L' + that.data.equipCode + '设置为恶意不归还吗？'
            that.personalModal.showModal(modalText, function () {
                that.notReturn(that);
            });
        },
        /**
         * 恶意不归还
         */
        notReturn: function (that) {
            lbbService.updateEquStat({
                equId: parseInt(that.data.equipCode),
                nowStat: 20,
                lbmid: parseInt(that.data.hospitalId)
            }, function (res) {
                that.toast.showToast('已标记恶意不归还', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },
        /**
         * 扫码获取控制盒编号
         */
        scanBoxCode: function () {
            let that = this;
            wx.scanCode({
                success(res) {
                    console.log('scanCode-->', res);
                    if (!that.data.changeCodeShow) {
                        that.setData({
                            changeCodeShow: true
                        })
                    }
                    let qrc = '';
                    let qrCode = res.result;
                    if (!qrCode) {
                        that.toast.showToast('二维码为空');
                        return;
                    }
                    let reg = /^([A-Za-z0-9]{2}:){5}([A-Za-z0-9]{2}){1}$/;
                    if (qrCode.indexOf(util.CONST_DATA.DEVICE_QRCODE_URL_PREFIX) == 0) {
                        //控制盒大二维码
                        var rst = qrCode.split('/');
                        qrc = rst[rst.length - 1];
                        that.data.scan_qrc = qrc;
                        console.log('qrc-->', Base64.decode(qrc));
                        var arr = Base64.decode(qrc).split('_')
                        // if(Base64.decode(qrc).indexOf('beijing_uzaubbjz_0719')!=-1){
                        if (arr[0] == 'beijing' && arr[2].indexOf('0719') == 0) {
                            lbbService.getQC({
                                qc: qrCode
                            }, res => {
                                console.log('getQC-->', res);
                                that.setData({
                                    largeCode: res.data.oldHpId,
                                    qc: qrCode
                                })
                            })
                        } else {
                            that.toast.showToast('请扫描贴在控制盒上的小二维码', 'warning', 3500);
                        }
                    } else if (reg.test(qrCode)) {
                        //控制盒小二维码
                        that.data.deviceId = qrCode;
                        that.data.mac = qrCode.replace(/:/g, '');
                        lbbService.getHpIdByMacId({
                            mac: that.data.mac
                        }, res => {
                            if (res.data && res.data.pileId) {
                                that.setData({
                                    smallCode: res.data.pileId,
                                    hospitalId: res.data.lbmId,
                                })
                            } else {
                                that.toast.showToast('获取编号失败');
                            }
                        })
                        return;
                    } else {
                        that.toast.showToast('二维码错误');
                        return;
                    }
                },
            })
        },
        /**
         * 绑定二维码
         */
        changeBrCode: function (e) {
            let that = this;
            console.log('largeCode>>', e);
            let qc = that.data.qc;
            let smallCode = e.detail.value.smallCode;
            that.setData({
                smallCode: smallCode
            })
            if (!smallCode || !qc) {
                that.toast.showToast('请扫码获取或输入编号', 'warning');
                return;
            }
            that.replaceBox(false);
        },
        replaceBox: function (isAllow) {
            let that = this;
            lbbService.replaceBox({
                isAllow: isAllow,
                lbmId: 0,
                originHid: that.data.smallCode,
                qc: Base64.encode(that.data.qc),
                rType: 'qrcode',
            }, function (res) {
                that.toast.showToast('已绑定成功', 'success');
                setTimeout(() => {
                    that.hideChangeCodeModal();
                    that.triggerEvent('getequipinfo');
                }, 2000)
            }, that.replaceBox)
        },

        //扫码获取rfid
        scanRfid: function () {
            let that = this;
            wx.scanCode({
                success(res) {
                    console.log('扫码结果>>', res)
                    that.setData({
                        rfidCode: res.result
                    })
                    lbbService.queryEquipByRfid({
                        rfid: that.data.rfidCode
                    }, function (res) {
                        that.setData({
                            newEquipCode: res.equipmentId,
                            rfidCode: ''
                        })
                    })
                }
            })
        },


        /**
         * 替换rfid
         */
        changeRfid: function (e) {
            let that = this;
            if (e) {
                var newEquipCode = e.detail.value.newEquipCode;
                that.setData({
                    newEquipCode: newEquipCode
                })
            }
            if (!that.data.newEquipCode) {
                that.toast.showToast('请输入或扫码获取编号', 'warning');
                return;
            }
            lbbService.replaceRfid({
                lbmId: parseInt(that.data.hospitalId),
                originEquId: that.data.equipCode.replace(/[^0-9]/ig, ""),
                newEquId: that.data.newEquipCode.replace(/[^0-9]/ig, ""),
                reason: ''
            }, function (res) {
                that.toast.showToast('rfid替换成功', 'success');
                that.hideChangeRfidModal();
            })
        },
        /**
         * 显示rfid不识别confirm
         */
        showRfidErrorModal: function (e) {
            let that = this;
            let equipCode = that.data.equipCode;
            let modalText = '确定将Z' + equipCode + '标记为RFID不识别吗？';
            that.personalModal.showModal(modalText, function (res) {
                that.rfidError(that);
            });
        },
        /**
         * 标记为rfid不识别
         */
        rfidError: function (that) {
            lbbService.rfidError({
                position: '',
                equId: parseInt(that.data.equipCode.replace(/[^0-9]/ig, "")),
                nowStat: 1,
                lbmid: parseInt(that.data.hospitalId)
            }, function (res) {
                that.toast.showToast('标记成功', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },

        /**
         * 更换读卡器
         */
        updateCard: function () {
            let that = this;
            let pileCode = that.data.equipCode;
            let modalText = '确定Z' + pileCode + '读卡器已更换吗？';
            that.personalModal.showModal(modalText, function () {
                lbbService.updateCard({
                    pileCode: pileCode,
                    cardReaderVer: '2.0'
                }, function (res) {
                    that.toast.showToast('标记成功', 'success');
                    setTimeout(function () {
                        that.triggerEvent('getequipinfo');
                    }, 2000)
                })
            })
        },
        /**
         * 查看桩位状态变化
         */
        toStatus: function () {
            let that = this;
            let equipCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/statChange/statChange?pileCode=' + equipCode,
            })
        },
        /**
         * 查看用户使用情况
         */
        toUsingSitua: function () {
            let that = this
            let pileCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/usingSitua/usingSitua?pileCode=' + pileCode,
            })
        },
        /**
         * 查看丢失轮椅情况
         */
        toLosingSitua: function () {
            let that = this
            let pileCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/losingSitua/losingSitua?pileCode=' + pileCode,
            })
        },
        /**
         * 查看插入开关情况
         */
        toSwitchStat: function () {
            let that = this
            let pileCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/switchStat/switchStat?pileCode=' + pileCode,
            })
        },
        /**
         * 查看锁钩开关情况
         */
        toHookStat: function () {
            let that = this
            let pileCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/hookStat/hookStat?pileCode=' + pileCode,
            })
        },
        /**
         * 蓝牙搜索超时统计
         */
        toBlueSearchTimeout: function () {
            let that = this
            let pileCode = that.data.equipCode;
            wx.navigateTo({
                url: '/pages/blueSearchTimeout/blueSearchTimeout?pileCode=' + pileCode,
            })
        },
        /**
         * 查看客服跟踪记录
         */
        toRecordDetail: function () {
            let tailRecord = this.data.tailRecord;
            wx.navigateTo({
                url: '/pages/recordDetail/recordDetail?time=' + tailRecord.tailTime + '&content=' + tailRecord.tailContent + '&equipCode=' + this.data.equipCode.replace(/[^0-9]/ig, ""),
            })
        },
        /**
         * 查看租借记录
         */
        toRecordList: function () {
            wx.navigateTo({
                url: '/pages/recordList/recordList?equipCode=' + this.data.equipCode.replace(/[^0-9]/ig, "") + '&equHospitalName=' + this.data.hospitalName,
            })
        },
        /**
         * 月租
         */
        toMonthRent: function () {
            wx.navigateTo({
                url: '/pages/equipOperate/monthRent/monthRent?equipCode=' + this.data.equipCode.replace(/[^0-9]/ig, "")
            })
        },
        /**
         * 显示确认丢失confirm
         */
        showLostTagModal: function () {
            let that = this;
            let equipCode = that.data.equipCode.replace(/[^0-9]/ig, "");
            let modalText = '确定L' + equipCode + '丢失吗？'
            lbbService.getLoseCategoryList({
                code: 'lose_reason_category'
            }, function (res) {
                let resData = [{
                    text: '其它',
                    value: 0
                }, ...res.data]
                that.setData({
                    lostClassification: resData,
                    classification: '0',
                    reasonFroLoss: ''
                })
            })
            that.setData({
                confirShow: true,
                modalText: modalText
            })
            //   that.personalModal.showModal(modalText, function(){
            //     that.lostTag(that);
            //   })
        },
        /**
         * 确认丢失
         */
        determineLoss: function () {
            let that = this
            console.log("id号", that.data.equipCode)
            if (that.data.reasonFroLoss || that.data.classification) {
                //找到当前的数据
                let curClassificattion = that.data.lostClassification.find(curr => curr.value == that.data.classification);
                if (!curClassificattion) {
                    //TODO 提示--请选择分类
                    wx.showToast({
                        title: '请选择分类',
                        icon: 'error',
                        duration: 1000
                      })
                    return false;
                }
                lbbService.updateEquStat({
                    equId: parseInt(that.data.equipCode),
                    nowStat: 10,
                    lbmid: parseInt(that.data.hospitalId),
                    loseReason: curClassificattion.text,
                    loseRemark: that.data.reasonFroLoss
                }, function (res) {
                    that.toast.showToast('已确认丢失', 'success');
                    that.setData({
                        confirShow: false,
                        reasonFroLoss: '',
                        classification: '0',
                    })
                    setTimeout(function () {
                        that.triggerEvent('getequipinfo');
                    }, 2000)
                })
            } else {
                wx.showToast({
                    title: '输入原因/类型',
                    icon: 'none',
                    duration: 1500
                })
            }
        },
        /**
         * 确认丢失
         */
        lostTag: function (that) {
            lbbService.updateEquStat({
                equId: parseInt(that.data.equipCode),
                nowStat: 10,
                lbmid: parseInt(that.data.hospitalId)
            }, function (res) {
                that.toast.showToast('已确认丢失', 'success');
                setTimeout(function () {
                    that.triggerEvent('getequipinfo');
                }, 2000)
            })
        },

        /**
         * 更换读卡器
         */
        updateCard: function () {
            let that = this;
            let pileCode = that.data.equipCode;
            let modalText = '确定Z' + pileCode + '读卡器已更换吗？'
            that.personalModal.showModal(modalText, function () {
                lbbService.updateCard({
                    pileCode: pileCode,
                    cardReaderVer: '2.0'
                }, function (res) {
                    that.toast.showToast('标记成功', 'success');
                    setTimeout(function () {
                        that.triggerEvent('getequipinfo');
                    }, 2000)
                })
            })
        },
    }
})
